package RecursionAndIteration;

import org.junit.Test;

public class Iteration {
	@Test 
	public void fun() {
		System.out.println(fibonacci(5));
	}
	public int fibonacci(int n) {
		if(n == 1 || n == 2) return 1;
		int result = 0, pre1 = 1, pre2 = 1;
		for(int i = 3; i <= n; i ++) {
			result = pre1 + pre2;
			pre1 = pre2;
			pre2 = result;
		}
		return result;
	}
}
